import Mock from 'mockjs';
import files from './file';

import { useAppStore } from '@/stores';

const url = {
  captcha: /\/mock\/captcha/, // 获取图片
  verify: /\/mock\/verify/, // 验证图片
};

Mock.mock(url.captcha, 'get', () => {
  const [originImg, jigsawImg] = files[useAppStore().index];

  if (useAppStore().index === 2) {
    useAppStore().setIndex(0);
  } else {
    useAppStore().setIndex(useAppStore().index + 1);
  }

  return {
    code: 1,
    data: {
      originalImageBase64: originImg,
      jigsawImageBase64: jigsawImg,
      secretKey: '123456',
      token: 'abcdef',
    },
    msg: '成功',
  };
});

Mock.mock(url.verify, 'post', (options: Record<string, any>) => {
  const body = JSON.parse(options.body);
  return {
    code: 1,
    data: {
      code: String(Mock.Random.natural(100000, 999999)),
    },
    msg: '',
  };
});
